Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing most node traversal usages #3009

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

olemartinorg
Copy link
Contributor

Description

My plan has, for a while, been to remove the node traversal concept entirely. When that 's done, we can also remove the LayoutPages, LayoutPage and even the LayoutNode object. At that point we can simplify the node hierarchy and refactor to remove the expression evaluation from the node generator.
This is just one step along that road, removing some of the node traversal usages.

Related Issue(s)

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

@olemartinorg olemartinorg added the kind/other Pull requests containing chores/repo structure/other changes label Feb 14, 2025
Ole Martin Handeland added 12 commits February 14, 2025 10:17
…odes() returned every node in pages in pageOrder, but nodeData included these implicitly hidden nodes. Removing generation of these nodes might break some use-cases, and I'll have to look into that more closely.
…rect method. This failed hard _sometimes_ in the pdf.ts test, seemingly because the clearTimeout() that ran here failed hard when freezing clocks in cy.testPdf(). I have no idea what's going on, or why this suddenly happened now, but it seems like getting rid of more cruft fixes it.
…d to the backend before it continues to test the pdf.
Ole Martin Handeland added 5 commits February 17, 2025 13:00
@olemartinorg olemartinorg changed the title Removing more node traversal usages Removing most node traversal usages Feb 17, 2025
@olemartinorg olemartinorg marked this pull request as ready for review February 17, 2025 17:18
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

Comment on lines +79 to +83
const componentOptions = NodesInternal.useShallowSelector((state) =>
Object.values(state.nodeData).map((nodeData) => ({
label: nodeData.layout.id,
value: `${nodeData.pageKey}|${nodeData.layout.id}`,
})),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A shallow selector will not do anything in this case no? You are returning a list, so the elements of the list are shallow-compared for equality, but you are creating new objects to populate the list every time so it will always fail the equality check on the first element

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely true! Sloppy mistake on my part. 🫣

Comment on lines -33 to +40
NodesInternal.useEffectWhenReady(() => {
useEffect(() => {
if (shouldSelectOptionAutomatically) {
if (nodeStore.getState().readiness !== NodesReadiness.Ready) {
requestAnimationFrame(() => setForceUpdate((prev) => prev + 1));
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like a quite the machine gun of re-renders 🤯 The original useEffectWhenReady was a bit complex maybe, what was the issue here?

Comment on lines +883 to +885
if (parent) {
return isHidden(state, 'node', parent?.layout.id, options);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, parent cannot be null 😅

Suggested change
if (parent) {
return isHidden(state, 'node', parent?.layout.id, options);
}
if (parent) {
return isHidden(state, 'node', parent.layout.id, options);
}

@@ -308,6 +308,8 @@ describe('PDF', () => {
});

cy.goto('changename');
cy.get(appFrontend.changeOfName.newFirstName).should('be.visible');
cy.waitUntilSaved();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this needed for the test to pass? 🤯 testPdf also waits for save before doing anything

Copy link
Member

@bjosttveit bjosttveit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just curious about the implications of the useEffectWhenReady-replacement in the three Effect*-components

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/other Pull requests containing chores/repo structure/other changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants